package com.traffic.managent.interceptor;

import java.util.UUID;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.traffic.managent.util.CxhomeUtils;

/**
 * 用户认证拦截器
 * 
 */
public class UserKeyInterceptor implements Interceptor {

	public void intercept(Invocation ai) {

		Controller controller = ai.getController();

		// 如果没有，就设置一个
		Object key = controller.getSessionAttr(CxhomeUtils.USER_KEY);
		if (key == null) {
			controller.setSessionAttr(CxhomeUtils.USER_KEY, UUID.randomUUID().toString());
		}

		ai.invoke();
	}
}
